package com.school.aftersalemanagement.global;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;

/**
 * Created by zht on 2017/04/07 9:04
 */

public abstract class BaseActivity extends AppCompatActivity {

//   public SubscriberOnNextListener getResultOnNext;
//   public static final APIFactory retrofitUtil = (APIFactory) APIFactory.getInstance();

//    private CompositeSubscription mCompositeSubscription;
//
//    public CompositeSubscription getCompositeSubscription() {
//
//        if (this.mCompositeSubscription == null) {
//            this.mCompositeSubscription = new CompositeSubscription();
//        }

//        return this.mCompositeSubscription;
//    }


//    public void addSubscription(Subscription s) {
//        if (this.mCompositeSubscription == null) {
//            this.mCompositeSubscription = new CompositeSubscription();
//        }
//
//        this.mCompositeSubscription.add(s);
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EventBus.getDefault().register(this);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        ButterKnife.bind(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
        work = false;
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        work = true;
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        EventBus.getDefault().unregister(this);
//        if (this.mCompositeSubscription != null) {
//            this.mCompositeSubscription.unsubscribe();
//        }
    }

    private Toast mToast = null;

    public void showShort(final String msg) {
        if (!TextUtils.isEmpty(msg)) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (mToast == null) {
                        mToast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
                    } else {
                        mToast.setText(msg);
                    }
                    mToast.show();
                }
            });

        }
    }
    public String getDeviceId(){
        TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = tm.getDeviceId();
        return deviceId;
    }

//    public void cancelToast(){
//        if (mToast != null){
//            mToast.cancel();
//        }
//    }

    public void startActivity(Class<? extends Activity> clazz) {
        Intent intent = new Intent();
        intent.setClass(this, clazz);
        startActivity(intent);
    }


    public void startActivity(Class<? extends Activity> clazz, String... data) {
        if (data.length % 2 == 1) {
            return;
        }
        Intent intent = new Intent();
        intent.setClass(this, clazz);
        for (int i = 0; i < data.length / 2; i++) {
            intent.putExtra(data[i * 2], data[i * 2 + 1]);
        }
        startActivity(intent);
    }

    private boolean work;
    public boolean isWork() {
        return work;
    }

//    public void alert(String msg) {
//        NormalDialog dialog = new NormalDialog(this);
//        dialog.content(msg).isTitleShow(false).btnNum(1).btnText("确定").show();
//    }
//
//    public NormalDialog confirm(String msg, OnBtnClickL on) {
//        NormalDialog dialog = new NormalDialog(this);
//        dialog.setOnBtnClickL(null, on);
//        dialog.content(msg).isTitleShow(false).btnNum(2).btnText("取消", "确定")
//                .show();
//        return dialog;
//    }
//
//
//    public String _ID() {
//        return getIntent().getStringExtra(_ID);
//    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onEventMainThread(BaseEvent event) {
//
//    }
}
